/*
 * @Date: 2023-01-22 02:17:37
 * @LastEditors: 恶名扬 2080156129@qq.com
 * @LastEditTime: 2023-01-24 06:38:09
 * @FilePath: \campus-repair-platform\server\routes\manage\admin.js
 */
const express = require("express")
// 创建路由对象
const router = express.Router()

const adminService = require("../../service/manage/admin")
// 验证表单中间件
const expressJoi = require('@escook/express-joi')
// 导入需要的验证规则对象
const { id_p_schema } = require("../../schema/common")
const {
  list_schema,
  add_schema,
  query_schema,
  update_schema,
  lock_schema
} = require("../../schema/manage/admin")


router.use((req, res, next) => {
  if (req.auth?.type === 3 || req.auth?.type === 4) next() // pass control to the next handler
  else res.errSend("没有权限访问", 10002)
})

// 获取管理员列表
router.get("/", expressJoi(list_schema), adminService.getAdminList)
// 获取管理员列表(报修管理)
router.get("/screen", adminService.screenAdminList)
// 查询管理员
router.get("/query", expressJoi(query_schema), adminService.queryAdminList)
// 添加管理员
router.post("/", expressJoi(add_schema), adminService.addAdmin)
// 获取管理员信息
router.get("/:id", expressJoi(id_p_schema), adminService.getInfoAdmin)
// 修改管理员信息
router.patch("/", expressJoi(update_schema), adminService.updateAdmin)
// 锁定管理员账号
router.post("/lock", expressJoi(lock_schema), adminService.lockAdmin)
// 删除管理员
router.delete(
  "/:id",
  expressJoi(id_p_schema),
  adminService.deleteAdmin
)

module.exports = router
